<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<% add_crumb t(:page_title, 'Profile Pictures') %>
<% content_for :page_title do %>{{#t}}Profile Pictures{{/t}}<% end %>

<% content_for :stylesheets do %>
<style>
.views .selected {
  font-weight: bold;
  font-size: 1.1em;
}
#avatars {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
}
#avatars tr .avatar_state {
  width: 50px;
}
#avatars td {
  border-bottom: 1px dotted #ddd;
  padding: 2px 0;
}
#avatars td.link_holder {
  text-align: right;
}
</style>
<% end %>
<h1>{{#t}}Profile Pictures{{/t}}</h1>
<div class="views">
  <span style="padding-right: 10px; font-weight: bold;"><%= before_label :show, 'Show' %> </span>
  <a href="?avatar_state=submitted" id="submitted_profile"  class="<%= 'selected' if @avatar_state == 'submitted' %>"><%= t(:submitted_link, { :zero => "Submitted", :one => "Submitted %{count}", :other => "Submitted %{count}" }, :count => @avatar_counts[:submitted] || 0) %></a> |
  <a href="?avatar_state=reported" id="reported_profile"class="<%= 'selected' if @avatar_state == 'reported' %>"><%= t(:reported_link, { :zero => "Reported", :one => "Reported %{count}", :other => "Reported %{count}" }, :count => @avatar_counts[:reported] || 0) %></a> |
  <a href="?avatar_state=re_reported" id="re_reported_profile" class="<%= 'selected' if @avatar_state == 're_reported' %>"><%= t(:re_reported_link, { :zero => "Approved, Re-Reported", :one => "Approved, Re-Reported %{count}", :other => "Approved, Re-Reported %{count}"}, :count => @avatar_counts[:re_reported] || 0) %></a> |
  <a href="?avatar_state=any" id="any_profile" class="<%= 'selected' if @avatar_state == 'any' %>"><%= t(:all_link, { :zero => "All", :one => "All %{count}", :other => "All %{count}" }, :count => @avatar_counts[:all] || 0) %></a>
</div>

<% if @users.empty? %>
  <h2 style="padding-top: 20px;">{{#t}}No Profile Pics to Show{{/t}}</h2>
<% end %>
<table id="avatars">
<% @users.each do |user| %>
  <tr class="<%= user.avatar_state %>">
    <td style="width: 54px;">
      <%= avatar user, url: nil %>
    </td>
    <td class="avatar_state">
      <% if user.avatar_state == :reported %>
        <span class="screenreader-only">{{#t}}Reported{{/t}}</span>
        {{> icons/warning}}
      <% end %>
      <% if user.avatar_state == :re_reported %>
        <span class="screenreader-only">{{#t}}Re-Reported{{/t}}</span>
        {{> icons/warning}}
      <% end %>
      <% if user.avatar_state == :locked %>
        <span class="screenreader-only">{{#t}}Locked{{/t}}</span>
        {{> icons/lock}}
      <% end %>
      <% if user.avatar_state == :approved %>
        <span class="screenreader-only">{{#t}}Approved{{/t}}</span>
        {{> icons/check}}
      <% end %>
    </td>
    <td>
      <div class="name"><a href="<%= user_url(user.id) %>"><%= user.name %></a></div>
      <div class="email"><%= user.email %></div>
    </td>
    <td class="link_holder">
      <div class="links">
        <a href="#" class="update_avatar_link approve_avatar_link" data-state="approved" style="<%= hidden unless user.avatar_approvable? %>">{{#t}}approve{{/t}}</a>
        <a href="#" class="update_avatar_link lock_avatar_link" data-state="locked" style="<%= hidden if user.avatar_state == :locked %>">{{#t}}lock{{/t}}</a>
        <a href="#" class="update_avatar_link unlock_avatar_link" data-state="approved" style="<%= hidden unless user.avatar_state == :locked %>">{{#t}}unlock{{/t}}</a>
        <a href="#" class="update_avatar_link reject_avatar_link" data-state="none">{{#t}}delete{{/t}}</a>
        <div style="display: none;">
          <a href="<%= update_avatar_image_url(user.id) %>" class="user_avatar_url">&nbsp;</a>
        </div>
      </div>
      <div class="progress" style="visibility: hidden;">
        {{#t}}Saving...{{/t}}"
      </div>
    </td>
  </tr>
<% end %>
</table>

<%= will_paginate(@users, :style=>"margin-bottom: 1em;") %>

<% js_bundle :manage_avatars %>
